package controllers;

import hibernate.Activity;
import hibernate.Schedule;
import hibernate.ScheduledActivity;
import hibernate.User;
import interfaces.IDbController;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class ScheduleController implements IDbController {

    DbController dbC;

    public ScheduleController(DbController d) {
        dbC = d;
    }

    public List<User> getStudentList(User u) {
        User t;
        List l = new ArrayList();
        l = dbC.getDbData(User.class, null);
        List tempList = new ArrayList();
        tempList.addAll(l);
        for (Iterator i = tempList.iterator(); i.hasNext();) {
            t = (User) i.next();
            if ((t.getTeacherId() == null) || (!t.getTeacherId().equals(u.getUserId()))) {
                l.remove(t);
            }
        }
        return l;
    }

    public List<Schedule> getScheduleList(User u) { //Student User
        Schedule s;
        List l = dbC.getDbData(Schedule.class, null);
        List tempList = new ArrayList();
        tempList.addAll(l);
        for (Iterator i = tempList.iterator(); i.hasNext();) {
            s = (Schedule) i.next();
            if (!(s.getUserId() == u.getUserId())) {
                l.remove(i);
            }
        }
        return l;
    }

    public List<Activity> getActivityList() {
        List l = dbC.getDbData(Activity.class, null);
        return l;
    }

    public List<ScheduledActivity> getScheduledActivities(Schedule u) {
        ScheduledActivity s;
        List l = dbC.getDbData(ScheduledActivity.class, null);
        List tempList = new ArrayList();
        tempList.addAll(l);
        for (Iterator i = tempList.iterator(); i.hasNext();) {
            s = (ScheduledActivity) i.next();
            if (!(s.getSchedId() == u.getSchedId())) {
                l.remove(i);
            }
        }
        return l;
    }
    
    public void saveScheduledActivities(List<ScheduledActivity> s){
        
        for (Iterator i = s.iterator(); i.hasNext();){
                dbC.saveDbData(i.next());
        }
        
    }
    
    public void saveScheduleList(List<Schedule> s){
        
    }
    
    public boolean isObjectUnique(List l, Object o) {
        return dbC.isObjectUnique(l, o);
        
    }

    @Override
    public List getDbData(Class c, Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDbDataCount(Class o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void saveDbData(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
